package org.ttitfly.workflow.engine.mode;

import org.ttitfly.workflow.engine.Process;
import org.ttitfly.workflow.engine.VirtualRunUnit;
import org.ttitfly.workflow.exception.ProcessRunException;


/**
 * 分支节点，所有后续单元都会被调度运行
 * 
 * @author 潘海春
 * @version 2009-9-10
 */
public class Fork extends VirtualRunUnit {

	/**
	 * 目标
	 */
	private String[] toUnits;

	/**
	 * 构造函数
	 * 
	 * @param parent
	 * @param name
	 * @param toUnits
	 */
	public Fork(Process parent, String name, String[] toUnits) {
		super(parent, name);
		if (toUnits == null || toUnits.length < 2) {
			throw new IllegalArgumentException("参数[toUnits]至少包含2个元素！");
		}
		this.toUnits = toUnits;
	}

	@Override
	public void run() throws ProcessRunException {
		for (String to : toUnits) {
			parent.dispatch(to);
		}
	}
}
